package cn.drenal.capcap.controller;

import cn.drenal.capcap.common.Response;
import cn.drenal.capcap.service.StatisticsService;
import cn.drenal.capcap.entity.vo.CategoryDistributionVO;
import cn.drenal.capcap.entity.vo.DashboardStatisticsVO;
import cn.drenal.capcap.entity.vo.RecentActivityVO;
import cn.drenal.capcap.entity.vo.UserGrowthTrendVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 统计数据控制器
 * 提供系统各类数据统计接口
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/statistics")
public class StatisticsController {

    private final StatisticsService statisticsService;

    /**
     * 获取仪表盘统计数据
     * 包括用户总数、作品总数、活动总数、评论总数及其环比增长率
     *
     * @return 统计数据
     */
    @GetMapping("/dashboard")
    public Response<DashboardStatisticsVO> getDashboardStatistics() {
        DashboardStatisticsVO data = statisticsService.getDashboardStatistics();
        return Response.success(data);
    }

    /**
     * 获取用户增长趋势数据
     *
     * @param days 天数，默认30天
     * @return 用户增长趋势数据
     */
    @GetMapping("/user/trend")
    public Response<UserGrowthTrendVO> getUserGrowthTrend(@RequestParam(value = "days", required = false) Integer days) {
        UserGrowthTrendVO data = statisticsService.getUserGrowthTrend(days);
        return Response.success(data);
    }

    /**
     * 获取作品分类分布数据
     *
     * @return 分类分布数据
     */
    @GetMapping("/category/distribution")
    public Response<List<CategoryDistributionVO>> getCategoryDistribution() {
        List<CategoryDistributionVO> data = statisticsService.getCategoryDistribution();
        return Response.success(data);
    }

    /**
     * 获取近期活动数据
     *
     * @param limit 获取数量，默认5条
     * @return 活动数据
     */
    @GetMapping("/activity/recent")
    public Response<List<RecentActivityVO>> getRecentActivities(@RequestParam(value = "limit", required = false) Integer limit) {
        List<RecentActivityVO> data = statisticsService.getRecentActivities(limit);
        return Response.success(data);
    }
}